package com.idmiss.qdpz.controller.admin.article;

import com.idmiss.qdpz.common.util.BeanUtils;
import com.idmiss.qdpz.common.CommonResult;
import com.idmiss.qdpz.common.page.PageResult;
import com.idmiss.qdpz.controller.admin.article.vo.ArticlePageReqVO;
import com.idmiss.qdpz.controller.admin.article.vo.ArticleRespVO;
import com.idmiss.qdpz.dal.dataobject.article.ArticleDO;
import com.idmiss.qdpz.service.article.ArticleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import static com.idmiss.qdpz.common.CommonResult.success;

@RestController
@RequestMapping("/qdpz/article")
@Validated
public class ArticleController {

    @Resource
    private ArticleService articleService;


    @GetMapping("/get")
    public CommonResult<ArticleRespVO> getArticle(@RequestParam("id") Integer id) {
        ArticleDO article = articleService.getArticle(id);
        return success(BeanUtils.toBean(article, ArticleRespVO.class));
    }

    @GetMapping("/page")
    public CommonResult<PageResult<ArticleRespVO>> getArticlePage(ArticlePageReqVO pageReqVO) {
        PageResult<ArticleDO> pageResult = articleService.getArticlePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ArticleRespVO.class));
    }

}
